# -*- coding: utf-8 -*-
########################################################################
#
# (c) 2010-2011 Markus Dittrich
#
# This program is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License Version 3 as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License Version 3 for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
#######################################################################

from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import absolute_import

from PyQt4.QtCore import (QString, Qt, SIGNAL, SLOT, QTime)
from PyQt4.QtGui import *
from caliente.gui.ui_add_event_dialog import Ui_AddEventWidget



class AddEventDialog(QDialog, Ui_AddEventWidget):

    def __init__(self, date, eventContainer, parent = None):
        """ Initialize widget. """
        
        QDialog.__init__(self, parent)
        self.setupUi(self)

        self.__eventInfo = eventContainer

        # set up date and time displays
        self.dateEdit.setDate(date)
        self.timeEdit.setTime(QTime(12,00))
        self.durationSpinBox.setSingleStep(15)
        self.durationSpinBox.setValue(30)



    def accept(self):
        """ This slot is called when ok is pressed. Checks that
        there is at least a subject and then stores the 
        content in the event data container. We also convert
        the actual values from Qt ones into a format that
        we can pass to Sqlite.

        """

        subject = self.subjectField.text()
        if not subject:
            QMessageBox.critical(self, "Subject missing",
                    "Please enter a subject for the new event!")
            return

        self.__eventInfo["title"]       = str(subject)
        self.__eventInfo["date"]        = self.dateEdit.date()
        self.__eventInfo["time"]        = \
            str(self.timeEdit.time().toString("hh:mm:ss"))
        self.__eventInfo["duration"]    = int(self.durationSpinBox.value())
        self.__eventInfo["description"] = \
            str(self.descriptionField.toPlainText())
            
        self.done(0)
